<?

if(!$tpl->is_cached($CONFIG['ModulesFolder'].$CONFIG['BlocksFolder'].'block.keywords_cloud.tpl'))
{
  $KeywordGroups = getTableAsArrayByKeyField($_SQL_TABLE['keyword_group'], 'id', '', array("active = 'y'"),'','id,title'.__FLANG.' AS title, linkname');
  $query = "
  			SELECT k.id, k.keyword_group, k.title".__FLANG." AS title, k.linkname, k.main, COUNT(n.id) AS count
  			FROM ".$_SQL_TABLE['keyword']." k
  			LEFT JOIN ".$_SQL_TABLE['news']." n ON FIND_IN_SET(k.id, n.keywords) > 0
  			WHERE
  					k.active = 'y'
  				AND n.active = 'y'
  				AND n.p_date <= NOW()
  				#AND n.a_date >= NOW()
  			GROUP BY k.id
  ";
  $dbSet->open($query);
  $Keywords = $dbSet->fetchRowsAll();

  foreach($Keywords as $name => $arr)
  {
  	$KeywordGroups[$arr['keyword_group']]['keywords'][] = $arr;
  }


  $tpl->assign('KeywordGroups', $KeywordGroups);
  $tpl->assign('Block', $Block);
}
  $tpl->cache_lifetime = 3600;
  $tpl->caching = 2;
  $Body = $tpl->fetch($CONFIG['ModulesFolder'].$CONFIG['BlocksFolder'].'block.keywords_cloud.tpl');

?>